// pages/wallet/wallet.js
const app = getApp();
import http from '../../utils/http.js';
import util from '../../utils/util.js';
import { businessWalletInfoApi,GetIncomeDetailsApi } from '../../utils/api.js';
import { GetStorewalletinfoApi,GetWalletCreditsApi } from '../../utils/newApi.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    selectList: [
      {
        name: '关注'
      },
      {
        name: '粉丝'
      },
    ],
    isShowSix:false,

    walletInfo:{},

    navList:[
      {
       name:'全部',
       id:0
      },
      {
       name:'入账',
       id:1
      },
      {
       name:'支出',
       id:2
      },
     ],
     activeIndex:0,
     paramData:{
      page:1,
      pageSize:20,
      type:0, //0全部 1收入 2支出
      store_id:'',
    },
    list:[],
    isLastPage:false
  },
  selectview(e){
    this.setData({
      activeIndex: e.currentTarget.dataset.index,
      list:[],
      'paramData.page':1,
      'paramData.type':e.currentTarget.dataset.id,
    })
    this.getStoreList();
  },
  // 获取列表
  getStoreList(){
    GetWalletCreditsApi(this.data.paramData).then(res=>{
      this.setData({
        list:this.data.list.concat(res.data.List),
        isLastPage:res.data.lastPage
      })
    })
  },
  businessWalletInfo(){
    GetStorewalletinfoApi({storeId: this.data.id}).then(res=>{
      this.setData({
        walletInfo:res.data
      })
    })
  },
close(e) {
    this.setData({
      isShowSix: false
    })
},
// 打开规则
clickRules() {
  this.setData({
    isShowSix: true
  })
},
jumpPage(e) {
  wx.navigateTo({
      url: e.currentTarget.dataset.url
  });
},
jumpPageBack(){
  wx.navigateBack({
    url: '/pages/home/home'
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      isAdmin : options.admin,
      id: options.businessId,
      'paramData.store_id': options.businessId,
      navTop: app.globalData.navTop,
      navHeight: app.globalData.navHeight,
      menuButtonObject: app.globalData.menuButtonObject
    })
    this.getStoreList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
     this.businessWalletInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(!this.data.isLastPage){
      this.data.paramData.page++
      this.getStoreList()
      console.log("说明到底了")
     }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})